home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
archiver
/
unix
/
unz50p1.zoo
/
VMS
/
vms.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-13
|
25KB
|
1,084 lines
/*************************************************************************
* *
* Copyright (C) 1992 Igor Mandrichenko. *
* Permission is granted to any individual or institution to use, copy, *
* or redistribute this software so long as all of the original files *
* are included unmodified, that it is not sold for profit, and that *
* this copyright notice is retained. *
* *
*************************************************************************/
/*
* vms.c by Igor Mandrichenko
* version 1.2-1
*
* This module contains routines to extract VMS file attributes
* from extra field and create file with these attributes. This
* source is mainly based on sources of file_io.c from UNZIP 4.1
* by Info-ZIP. [Info-ZIP note: very little of this code is from
* file_io.c; it has virtually been written from the ground up.
* Of the few lines which are from the older code, most are mine
* (G. Roelofs) and I make no claims upon them. On the contrary,
* my/our thanks to Igor for his contributions!]
*/
/*
* Revision history:
* 1.0-1 Mandrichenko 16-feb-1992
* Recognize -c option
* 1.0-2 Mandrichenko 17-feb-1992
* Do not use ASYnchroneous mode.
* 1.0-3 Mandrichenko 2-mar-1992
* Make code more standard
* Use lrec instead of crec -- unzip4.2p does not provide
* crec now.
* 1.1 Mandrichenko 5-mar-1992
* Make use of asynchronous output.
* Be ready to extract RMS blocks of invalid size (because diff
* VMS version used to compress).
* 1.1-1 Mandrichenko 11-mar-1992
* Use internal file attributes saved in pInfo to decide
* if the file is text. [GRR: temporarily disabled, since
* no way to override and force binary extraction]
* 1.1-2 Mandrichenko 13-mar-1992
* Do not restore owner/protection info if -X not specified.
* 1.1-3 Mandrichenko 30-may-1992
* Set revision date/time to creation date/time if none specified
* Take quiet flag into account.
* 1.1-4 Cave Newt 14-jun-1992
* Check zipfile for variable-length format (unzip and zipinfo).
* 1.2 Mandrichenko 21-jun-1992
* Use deflation/inflation for compression of extra blocks
* Free all allocated space
* 1.2-1 Mandrichenko 23-jun-1992
* Interactively select an action when file exists
*/
#ifdef VMS /* VMS only ! */
#ifndef SYI$_VERSION
#define SYI$_VERSION 4096 /* VMS 5.4 definition */
#endif
#ifndef VAXC
/* This definition may be missed */
struct XAB {
unsigned char xab$b_cod;
unsigned char xab$b_bln;
short int xabdef$$_fill_1;
char *xab$l_nxt;
};
#endif
#include "unzip.h"
#include <ctype.h>
#include <descrip.h>
#include <syidef.h>
#define ERR(s) !((s) & 1)
#define BUFS512 8192*2 /* Must be a multiple of 512 */
/*
* Local static storage
*/
static struct FAB fileblk;
static struct XABDAT dattim;
static struct XABRDT rdt;
static struct RAB rab;
static struct FAB *outfab = 0;
static struct RAB *outrab = 0;
static struct XABFHC *xabfhc = 0;
static struct XABDAT *xabdat = 0;
static struct XABRDT *xabrdt = 0;
static struct XABPRO *xabpro = 0;
static struct XABKEY *xabkey = 0;
static struct XABALL *xaball = 0;
struct XAB *first_xab = 0L, *last_xab = 0L;
static char query = 0;
static int text_file = 0;
static char locbuf[BUFS512];
static int loccnt = 0;
static char *locptr;
static int WriteBuffer();
static int _flush_blocks();
static int _flush_records();
static byte *extract_block();
static void message();
static int get_vms_version();
static void free_up();
static int replace();
struct bufdsc
{
struct bufdsc *next;
byte *buf;
int bufcnt;
};
static struct bufdsc b1, b2, *curbuf;
static byte buf1[BUFS512], buf2[BUFS512];
int check_format() /* return non-0 if format is variable-length */
{
int rtype;
struct FAB fab;
fab = cc$rms_fab;
fab.fab$l_fna = zipfn;
fab.fab$b_fns = strlen(zipfn);
sys$open(&fab);
rtype = fab.fab$b_rfm;
sys$close(&fab);
if (rtype == FAB$C_VAR || rtype == FAB$C_VFC)
{
fprintf(stderr,
"\n Error: zipfile is in variable-length record format. Please\n\
run \"bilf l %s\" to convert the zipfile to stream-LF\n\
record format. (Bilf.exe, bilf.c and make_bilf.com are included\n\
in the VMS UnZip source distribution.)\n\n", zipfn);
return 2; /* 2: error in zipfile */
}
return 0;
}
#ifndef ZIPINFO
int create_output_file()
{ /* return non-0 if sys$create failed */
int ierr, yr, mo, dy, hh, mm, ss;
char timbuf[24]; /* length = first entry in "stupid" + 1 */
int attr_given = 0; /* =1 if VMS attributes are present in
* extra_field */
rab = cc$rms_rab; /* fill FAB & RAB with default values */
fileblk = cc$rms_fab;
text_file =/* pInfo->text || */aflag || cflag;
if (attr_given = find_vms_attrs())
{
text_file = 0;
if (cflag)
{
printf("Cannot put VMS file %s to stdout.\n",
filename);
free_up();
return 50;
}
}
if (!attr_given)
{
outfab = &fileblk;
outfab->fab$l_xab = 0L;
if (text_file)
{
outfab->fab$b_rfm = FAB$C_VAR; /* variable length records */
outfab->fab$b_rat = FAB$M_CR; /* carriage-return carriage ctrl */
}
else
{
outfab->fab$b_rfm = FAB$C_STMLF; /* stream-LF record format */
outfab->fab$b_rat = FAB$M_CR; /* carriage-return carriage ctrl */
}
}
if (!cflag)
outfab->fab$l_fna = filename;
else
outfab->fab$l_fna = "sys$output:";
outfab->fab$b_fns = strlen(outfab->fab$l_fna);
if ((!attr_given) || xabdat == 0 || xabrdt == 0) /* Use date/time info
* from zipfile if
* no attributes given
*/
{
static char *month[] =
{"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
/* fixed-length string descriptor: */
struct dsc$descriptor stupid =
{23, DSC$K_DTYPE_T, DSC$K_CLASS_S, timbuf};
yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
dy = (lrec.last_mod_file_date & 0x1f);
hh = (lrec.last_mod_file_time >> 11) & 0x1f;
mm = (lrec.last_mod_file_time >> 5) & 0x3f;
ss = (lrec.last_mod_file_time & 0x1f) * 2;
dattim = cc$rms_xabdat; /* fill XABs with default values */
rdt = cc$rms_xabrdt;
sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", dy, month[mo], yr,
hh, mm, ss);
sys$bintim(&stupid, &dattim.xab$q_cdt);
memcpy(&rdt.xab$q_rdt, &dattim.xab$q_cdt, sizeof(rdt.xab$q_rdt));
if ((!attr_given) || xabdat == 0L)
{
dattim.xab$l_nxt = outfab->fab$l_xab;
outfab->fab$l_xab = &dattim;
}
}
outfab->fab$w_ifi = 0; /* Clear IFI. It may be nonzero after ZIP */
ierr = sys$create(outfab);
if (ierr == RMS$_FEX)
ierr = replace();
if (ierr == 0) /* Canceled */
return free_up(), 1;
if (ERR(ierr))
{
char buf[256];
sprintf(buf, "[ Cannot create output file %s ]\n", filename);
message(buf, ierr);
message("", outfab->fab$l_stv);
free_up();
return (1);
}
if (!text_file && !cflag) /* Do not reopen text files and stdout
* Just open them in right mode */
{
/*
* Reopen file for Block I/O with no XABs.
*/
if ((ierr = sys$close(outfab)) != RMS$_NORMAL)
{
#ifdef DEBUG
message("[ create_output_file: sys$close failed ]\n", ierr);
message("", outfab->fab$l_stv);
#endif
fprintf(stderr, "Can't create output file: %s\n", filename);
free_up();
return (1);
}
outfab->fab$b_fac = FAB$M_BIO | FAB$M_PUT; /* Get ready for block
* output */
outfab->fab$l_xab = 0L; /* Unlink all XABs */
if ((ierr = sys$open(outfab)) != RMS$_NORMAL)
{
char buf[256];
sprintf(buf, "[ Cannot open output file %s ]\n", filename);
message(buf, ierr);